package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.gdms.service.ApplicationService;
import com.zr.gdms.serviceimpl.ApplicationServiceImpl;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
 * 得到申请表
 * @author 李培宁
 *
 */
public class ApplicationControllerLPN extends HttpServlet{

	ApplicationService as = new ApplicationServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		int page = Integer.parseInt(req.getParameter("page"));
		int rows  = Integer.parseInt(req.getParameter("rows"));
		String apptype = "离职申请";
		HttpSession  session = req.getSession();
		JSONArray j = as.getAllApplication((page-1)*rows, rows, apptype);
//		JSONObject j2 = JSONObject.fromObject(as.getApplicationCount(apptype));
//		j.add(j2);
		JSONObject j2 = new JSONObject();
		j2.put("total", as.getApplicationCount(apptype));
		j2.put("rows", j);
		session.setAttribute("application", j);
		PrintWriter pw = resp.getWriter();
		pw.write(j2.toString());
		pw.flush();
		pw.close();
	}
}
